﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BoAddonBiz_FreightForwarder.BusinessBase;
using SAPbouiCOM;
using System.Text.RegularExpressions;

namespace BoAddonBiz_FreightForwarder.Land
{
    [ControlB1Form(IsNew = true, FormType = B1FormTypes.ado_AVA_LN_BusinessOperation)]
    class B1Form_BusinessOperation_Land : B1Form_BusinessOperation_Base
    {
        #region override
        protected override string AVA_OBNO { get { return "@AVA_LN_OBNO"; } }
        protected override string AVA_BNO1 { get { return "@AVA_LN_BNO1"; } }
        protected override string AVA_BNO2 { get { return "@AVA_LN_BNO2"; } }
        protected override string AVA_BNO3 { get { return "@AVA_LN_BNO3"; } }
        protected override string AVA_BNO4 { get { return "@AVA_LN_BNO4"; } }
        protected override string AVA_BNO5 { get { return "@AVA_LN_BNO5"; } }
        protected override string AVA_ODLG { get { return "@AVA_LN_ODLG"; } }
        protected override string AVA_DLG1 { get { return "@AVA_LN_DLG1"; } }
        protected override string AVA_DLG2 { get { return "@AVA_LN_DLG2"; } }
        protected override string AVA_DLG3 { get { return "@AVA_LN_DLG3"; } }
        protected override string AVA_DLG6 { get { return "@AVA_LN_DLG6"; } }
        protected override string AVA_AirOrder { get { return "AVA_FF_AirOrder"; } }
        protected override string AVA_AirOrderUsed { get { return "AVA_FF_AirOrderUsed"; } }
        protected override string AVA_OAOU { get { return "@AVA_FF_OAOU"; } }
        protected override string AVA_OAOD { get { return "@AVA_FF_OAOD"; } }
        protected override string SourceObject { get { return "AVA_LN_Delegate"; } }
        protected override string BusinessType { get { return "LN"; } }
        protected override string[] SumMapping
        {
            get { return new string[] { "U_Quantity:U_Quantity", "U_GrossWeight:U_GrossWeight", "U_BillingWeight:U_BillingWeight", "U_Volume:U_Volume", "U_CargoValue:U_CargoValue" }; }
        }
        protected override string[] CB_LABEL_UDS_DBDS_OBJECT_TABLE_DESC
        {
            get
            {
                return new string[] {
            "cb_opup:btn_opup:OPUP_UID:U_IsPickup:AVA_LN_Pickup:@AVA_LN_OPUP:提货",
            "cb_oisu:btn_oisu:OISU_UID:U_IsInsure:AVA_LN_Insure:@AVA_LN_OISU:投保",
            "cb_oatc:btn_oact:OATC_UID:U_IsCustoms:AVA_LN_ApplyCustoms:@AVA_LN_OATC/@AVA_LN_ATC1:出口报关/报检",
            "cb_ostg:btn_ostg:OSTG_UID:U_IsWarehouse:AVA_LN_Storage:@AVA_LN_OSTG/@AVA_LN_STG1:仓储",
            "cb_odlv:btn_odlv:ODLV_UID:U_IsDelivery:AVA_LN_Deliver:@AVA_LN_ODLV:送货",
            "cb_octc:btn_octc:OCTC_UID:U_IsClearance:AVA_LN_Clearance:@AVA_LN_OCTC/@AVA_LN_CTC1:进口报关/报检",
            "cb_oarp:btn_oarp:OARP_UID:U_IsArrivePort:AVA_LN_ArrivePort:@AVA_LN_OARP:到港"
            };
            }
        }

        public B1Form_BusinessOperation_Land()
            : base()
        {
            this.frm_ItemEvent += new SAPBoAddon.IB1FormEvents.B1ItemEventEventHandler(B1Form_BusinessOperation_Air_frm_ItemEvent);
            this.frm_FormDataEvent += new SAPBoAddon.IB1FormEvents.B1FormDataEventEventHandler(B1Form_BusinessOperation_Air_frm_FormDataEvent);
            this.frm_MenuEvent += new SAPBoAddon.IB1FormEvents.B1MenuEventEventHandler(B1Form_BusinessOperation_Air_frm_MenuEvent);
            this.frm_ChooseFormListEvent += new SAPBoAddon.IB1FormEvents.B1ChooseFormListEventEventHandler(B1Form_BusinessOperation_Air_frm_ChooseFormListEvent);
        }

        void B1Form_BusinessOperation_Air_frm_ChooseFormListEvent(SAPBoAddon.B1AddonBase.B1ChooseFormList pVal, ref bool BubbleEvent)
        {
            if (pVal.Before_Action)
            {
                SAPbouiCOM.ChooseFromList cfl = this.CurrentForm.ChooseFromLists.Item(pVal.ChooseFromListUID);
                SAPbouiCOM.Conditions cons;
                SAPbouiCOM.Condition con;
                switch (pVal.ChooseFromListUID)
                {
                    case "CFL_OCRD_D"://指定代理
                        cons = new SAPbouiCOM.Conditions();
                        con = cons.Add();
                        con.Alias = "QryGroup5";
                        con.CondVal = "Y";
                        con.Operation = SAPbouiCOM.BoConditionOperation.co_EQUAL;
                        con.Relationship = BoConditionRelationship.cr_OR;
                        con = cons.Add();
                        con.Alias = "QryGroup6";
                        con.CondVal = "Y";
                        con.Operation = SAPbouiCOM.BoConditionOperation.co_EQUAL;
                        con.Relationship = BoConditionRelationship.cr_OR;
                        con = cons.Add();
                        con.Alias = "QryGroup7";
                        con.CondVal = "Y";
                        con.Operation = SAPbouiCOM.BoConditionOperation.co_EQUAL;
                        con.Relationship = BoConditionRelationship.cr_AND;
                        con = cons.Add();
                        con.Alias = "validFor";
                        con.CondVal = "Y";
                        con.Operation = SAPbouiCOM.BoConditionOperation.co_EQUAL;
                        cfl.SetConditions(cons);
                        break;
                    case "CFL_OCRD_ED"://目的港代理
                        cons = new SAPbouiCOM.Conditions();
                        con = cons.Add();
                        con.Alias = "QryGroup7";
                        con.CondVal = "Y";
                        con.Operation = SAPbouiCOM.BoConditionOperation.co_EQUAL;
                        con.Relationship = BoConditionRelationship.cr_AND;
                        con = cons.Add();
                        con.Alias = "validFor";
                        con.CondVal = "Y";
                        con.Operation = SAPbouiCOM.BoConditionOperation.co_EQUAL;
                        cfl.SetConditions(cons);
                        break;
                    case "CFL_OCRD_TP"://中转港代理
                        cons = new SAPbouiCOM.Conditions();
                        con = cons.Add();
                        con.Alias = "QryGroup7";
                        con.CondVal = "Y";
                        con.Operation = SAPbouiCOM.BoConditionOperation.co_EQUAL;
                        con.Relationship = BoConditionRelationship.cr_AND;
                        con = cons.Add();
                        con.Alias = "validFor";
                        con.CondVal = "Y";
                        con.Operation = SAPbouiCOM.BoConditionOperation.co_EQUAL;
                        cfl.SetConditions(cons);
                        break;
                    case "CFL_OCRD_T":
                        cons = new SAPbouiCOM.Conditions();
                        con = cons.Add();
                        con.Alias = "QryGroup7";
                        con.CondVal = "Y";
                        con.Operation = SAPbouiCOM.BoConditionOperation.co_EQUAL;
                        con.Relationship = BoConditionRelationship.cr_AND;
                        con = cons.Add();
                        con.Alias = "validFor";
                        con.CondVal = "Y";
                        con.Operation = SAPbouiCOM.BoConditionOperation.co_EQUAL;
                        cfl.SetConditions(cons);
                        break;
                    case "CFL_OCRD_F"://承运人
                        cons = new SAPbouiCOM.Conditions();
                        con = cons.Add();
                        con.Alias = "QryGroup5";
                        con.CondVal = "Y";
                        con.Operation = SAPbouiCOM.BoConditionOperation.co_EQUAL;
                        con.Relationship = BoConditionRelationship.cr_OR;
                        con = cons.Add();
                        con.Alias = "QryGroup6";
                        con.CondVal = "Y";
                        con.Operation = SAPbouiCOM.BoConditionOperation.co_EQUAL;
                        con.Relationship = BoConditionRelationship.cr_OR;
                        con = cons.Add();
                        con.Alias = "QryGroup7";
                        con.CondVal = "Y";
                        con.Operation = SAPbouiCOM.BoConditionOperation.co_EQUAL;
                        con.Relationship = BoConditionRelationship.cr_AND;
                        con = cons.Add();
                        con.Alias = "validFor";
                        con.CondVal = "Y";
                        con.Operation = SAPbouiCOM.BoConditionOperation.co_EQUAL;
                        cfl.SetConditions(cons);
                        break;
                }
            }
        }

        void B1Form_BusinessOperation_Air_frm_MenuEvent(SAPBoAddon.B1AddonBase.B1MenuEvent pVal, ref bool BubbleEvent)
        {
            if (pVal.BeforeAction)
            {

            }
            else
            {
                if (pVal.MenuUID == "1287")
                {
                    SBLOtherPayChange(this.CurrentForm, this.CurrentForm.DataSources.DBDataSources.Item(AVA_BNO4).GetValue("U_OtherPayMethod", this.CurrentForm.DataSources.DBDataSources.Item(AVA_BNO4).Offset).Trim());//2012-05-30 12:08:52 by Webb.Wen
                }
            }
        }


        void B1Form_BusinessOperation_Air_frm_ItemEvent(SAPBoAddon.B1AddonBase.B1ItemEvent pVal, ref bool BubbleEvent)
        {
            if (pVal.Before_Action)
            {
                #region 主单号录入格式限制
                // by WangPeng 2014年5月9日11:13:56
                //if (pVal.ItemUID == "1000013" && pVal.EventType == BoEventTypes.et_VALIDATE)
                //{
                //    String MBLNumber = SAPBoAddon.B1Assistant.Item.GetValue(CurrentForm, pVal.ItemUID).ToString();
                //    if (string.IsNullOrEmpty(MBLNumber)) return;
                //    //if (MBLNumber.Substring(3, 1) != "-")
                //    if (!new Regex(@"\w{3}-\w{8}").Match(MBLNumber).Success)
                //    {
                //        SBOApp.MessageBox("主单号的格式为：XXX-XXXXXXXX\r\n请检查录入的是否正确？");
                //        BubbleEvent = false;
                //    }
                //}

                #endregion
            }
            else
            {
                if (pVal.ItemUID == "tab_0" && pVal.EventType == BoEventTypes.et_ITEM_PRESSED)
                {
                    CurrentForm.PaneLevel = 1;
                }
                if (pVal.ItemUID == "tab_1" && pVal.EventType == BoEventTypes.et_ITEM_PRESSED)
                {
                    CurrentForm.PaneLevel = 2;
                }
                if (pVal.ItemUID == "tab_2" && pVal.EventType == BoEventTypes.et_ITEM_PRESSED)
                {
                    CurrentForm.PaneLevel = 3;
                }
                if (pVal.ItemUID == "tab_3" && pVal.EventType == BoEventTypes.et_ITEM_PRESSED)
                {
                    CurrentForm.PaneLevel = 4;
                }
                if (pVal.ItemUID == "tab_4" && pVal.EventType == BoEventTypes.et_ITEM_PRESSED)
                {
                    CurrentForm.PaneLevel = 5;
                }
                #region 计算计费重
                if (pVal.ItemUID == "cargo_8" && pVal.ItemChanged)
                {
                    DBDataSource dbds1 = this.CurrentForm.DataSources.DBDataSources.Item(AVA_BNO1);
                    dbds1.SetValue("U_BillingWeight", dbds1.Offset, SAPBoAddon.B1Assistant.Item.GetValue(this.CurrentForm, pVal.ItemUID).ToString());
                }
                #endregion
            }
        }

        void B1Form_BusinessOperation_Air_frm_FormDataEvent(SAPBoAddon.B1AddonBase.B1BusinessObjectInfo pVal, ref bool BubbleEvent)
        {
            if (pVal.BeforeAction)
            {
            }
            else
            {
                if (pVal.EventType == BoEventTypes.et_FORM_DATA_ADD && pVal.ActionSuccess)//主对象保存成功之后
                {
                    //主单领用
                    //AddAirOrderUsed(); by WangPeng 2012年9月20日 10:14:36
                }
                if (pVal.EventType == BoEventTypes.et_FORM_DATA_LOAD && pVal.ActionSuccess)
                {
                    SBLOtherPayChange(this.CurrentForm, this.CurrentForm.DataSources.DBDataSources.Item(AVA_BNO4).GetValue("U_OtherPayMethod", this.CurrentForm.DataSources.DBDataSources.Item(AVA_BNO4).Offset).Trim());//2012-05-30 12:08:41 by Webb.Wen
                }
            }

        }

        protected override void FormInfoSetting(SAPBoAddon.B1FormSetting FormSetting)
        {
            FormSetting.FormType = B1FormTypes.ado_AVA_LN_BusinessOperation;
            FormSetting.FormFileName = "AVA_LN_BusinessOperaForm.srf";
            #region 窗体控件控制
            string[] NewModeItms = new string[] { "274", "275", "277", "278", "279", "276", "268", "269", "270", "271", "272", "273" };
            #region 添加状态
            FormSetting.FormModeSetting.itmNewModeEnable = Utils.GetFormItems(FormSetting.FormXmlDocument, true, NewModeItms);
            FormSetting.FormModeSetting.itmNewModeDisable = NewModeItms;
            #endregion
            #endregion
            base.FormInfoSetting(FormSetting);
        }
        protected override void FormEditModeChange(SAPBoAddon.frmItemEditMode frmEditMode)
        {
            base.FormEditModeChange(frmEditMode);
            switch (frmEditMode)
            {
                case SAPBoAddon.frmItemEditMode.fe_AddMode:
                    this.CurrentForm.DataSources.DBDataSources.Item(AVA_BNO3).SetValue("U_NCV", 0, "N.C.V");
                    this.CurrentForm.DataSources.DBDataSources.Item(AVA_BNO3).SetValue("U_NVD", 0, "N.V.D");
                    this.CurrentForm.DataSources.DBDataSources.Item(AVA_BNO4).SetValue("U_NCV", 0, "N.C.V");
                    this.CurrentForm.DataSources.DBDataSources.Item(AVA_BNO4).SetValue("U_NVD", 0, "N.V.D");
                    break;

            }
        }
        #endregion
    }
}
